package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Cart;
import com.itheima.reggie.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.awt.*;
import java.util.List;

/**
 * @Name CartController
 * @Author stella
 * @Date 2023-03-08 8:09 PM
 */
@RestController
@RequestMapping("/cart")
public class CartController {
    @Autowired
    private CartService cartService;

    /**
     * 购物车新增
     * @param cartParam
     * @return
     */
    @PostMapping("/add")
    public ResultInfo add(@RequestBody Cart cartParam){
        Cart cart = cartService.add(cartParam);
        return ResultInfo.success(cart);
    }

    /**
     * 查询购物车
     * @return
     */
    @GetMapping("/list")
    public ResultInfo list(){
        List<Cart> cartList =cartService.list();
        return ResultInfo.success(cartList);
    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    public ResultInfo clean(){
        cartService.clean();
        return ResultInfo.success();
    }

    /**
     * 购物车减少修改
     * @return
     */
    @PostMapping("/sub")
    public ResultInfo sub(@RequestBody  Cart cart){
        Cart cart1 = cartService.sub(cart);
        return ResultInfo.success(cart1);
    }
}
